<?php $this->renderPartial('../common/_header');?>
<div class="container my-container">
    <div class="row">
        <div class="col col-lg-3">
            <?php $this->renderPartial('//common/'.($this->user ? 'menu' : 'menu_guest'));?>
        </div>
        <div class="col col-lg-9">

            <div id="content-manager-email">

                <div class="col col-lg-12">
                    <div class="page-header">
                        <h2>Danh sách email</h2>
                    </div>

                    <div id="email_list">
                        <?php $this->renderPartial('manage_email_list', array('userEmails' => $this->user->userEmails))?>
                    </div>
                </div>   

                <div class="col col-lg-6">  

                    <div class="page-header">
                        <h3>Thêm email</h3>
                    </div>
                    <?php $form=$this->beginWidget('CActiveForm', array(
                            'id'=>'add-email-form',
                            'enableClientValidation'=>true,
                            'clientOptions'=>array(
                                'validateOnSubmit' => true,
                                'validateOnChange' => true,
                            ),
                            'enableAjaxValidation'=>false,
                            'htmlOptions' => array('class' => 'form-horizontal my-form')
                        )); ?>


                    <div class="row">
                        <div class="col col-lg-8">
                            <?php echo $form->textField($emailModel,'email',array('placeholder'=> $emailModel->getAttributeLabel('email'),'maxlength'=>255)); ?>
                            <?php echo $form->error($emailModel,'email');?>
                        </div>
                        <div class="col col-lg-4">
                            <button class="btn btn-primary" type="submit">
                                <i class="icon-plus"></i> Thêm
                            </button>  
                        </div>
                    </div> 

                    <?php $this->endWidget(); ?>
                </div>
                <div class="col col-lg-6">  
                    <div class="page-header">
                        <h3>Thêm OpenID</h3>
                    </div>

                    <div class="my-openid large">
                        <a class="openid_popup decoration-none" rel="tooltip" data-placement="top" title="Thêm tài khoản Facebook" href="<?php echo $this->createUrl('/user/page/manageEmail', array('service' => 'facebook'))?>"><i class="icon-facebook-sign"></i></a> 
                        <a class="openid_popup decoration-none" rel="tooltip" data-placement="top" title="Thêm tài khoản Google" href="<?php echo $this->createUrl('/user/page/manageEmail', array('service' => 'google'))?>"><i class="icon-google-plus-sign"></i></a> 
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<script>
    $('input[name="is_main"]').live('change', function(){
        $.post('<?php echo $this->createUrl('/user/page/ajaxUpdateEmailList')?>', {
            action: 'update_main', 
            email_id: $(this).val()
            }, function(data){
                $('#email_list').html(data);    
        });    
    }); 

    $('.email_remove a').live('click', function(e){
        e.preventDefault();

        if(confirm('Bạn có chắc chắn muốn loại bỏ email '+ $(this).attr('email') + ' ?')){
            $.post('<?php echo $this->createUrl('/user/page/ajaxUpdateEmailList')?>', {
                action: 'remove', 
                email_id: $(this).attr('email_id')
                }, function(data){
                    $('#email_list').html(data);    
            });    
        }                                                                                                                                            
    });                                                                                                                                                 
</script>